from langchain_core.output_parsers import XMLOutputParser
from langchain_core.prompts import PromptTemplate
from langchain_openai import ChatOpenAI, OpenAI

# 大模型
llm = OpenAI(
    api_key="sk-VowKQBUMIkSND8WScNJtDLqf3FyqWHQ43LMVUXH1m6GZaopA",
    base_url="https://ai.nengyongai.cn/v1"
)


def test1():
    # pip install defusexml


    action_query = "生成周星驰的简化电影作品列表,按照最新的顺序降序"
    parser = XMLOutputParser()
    prompt = PromptTemplate(
        template="回答用户的查询.\n{format_instructions}\n{query}\n",
        input_variables=["query"],
        partial_variables={"format_instructions": parser.get_format_instructions()},
    )
    chain = prompt | llm
    response = chain.invoke({"query": action_query})
    xml_output = parser.parse(response)
    print(xml_output)
